package com.twu.biblioteca.Library1;

import com.twu.biblioteca.Book1.Book;
import com.twu.biblioteca.Movie1.Movie;
import com.twu.biblioteca.Member1.Member;

import java.util.*;
public class Library
{
    ArrayList<Book> book = new ArrayList<Book>();
    Book book1,book2,book3,book4;
    ArrayList<Movie> movie=new ArrayList<Movie>();
    Movie movie1,movie2,movie3,movie4,movie5,movie6,movie7,movie8,movie9,movie10,movie11,movie12,movie13,movie14,movie15;
    ArrayList<Member> member = new ArrayList<Member>();
    Member member1,member2,member3,member4;

    public Library()
    {
        //To add book to the library
        book1=new Book(1,"ramayana","valmiki","Story",5);
        book2=new Book(2,"Bharatha","vyasa","Story",6);
        book3=new Book(3,"Letus C","yashwant","Computer",1);
        book4=new Book(4,"RDBMS","ramesh","Computer",0);
        book.add(book1);
        book.add(book2);
        book.add(book3);
        book.add(book4);


        //To add movies
        movie1=new Movie("Billa  ",1992,"vishnu","9");
        movie2=new Movie("Poo    ",1993,"sasi  ","8");
        movie3=new Movie("I      ",1994,"shankar","10");
        movie4=new Movie("Kadal  ",1995,"Mani  ","10");
        movie5=new Movie("Ravanan",1996,"Mani  ","10");
        movie6=new Movie("Alai   ",1997,"Mani  ","4");
        movie7=new Movie("Ko     ",1998,"Anand ","10");
        movie8=new Movie("Indian ",1999,"Shankar","10");
        movie9=new Movie("NEP    ",1992,"gowtham","10");
        movie10=new Movie("VTV   ",1992,"gowtham","n/a");
        movie11=new Movie("Singam",1992,"Hari   ","10");
        movie12=new Movie("Boss  ",1992,"rajesh ","5");
        movie13=new Movie("xxxx  ",1992,"def    ","10");
        movie14=new Movie("nnty  ",1992,"abc    ","8");
        movie15=new Movie("brgg  ",1992,"xxr    ","4");
        movie.add(movie1);
        movie.add(movie2);
        movie.add(movie3);
        movie.add(movie4);
        movie.add(movie5);
        movie.add(movie6);
        movie.add(movie7);
        movie.add(movie8);
        movie.add(movie9);
        movie.add(movie10);
        movie.add(movie11);
        movie.add(movie12);
        movie.add(movie13);
        movie.add(movie14);
        movie.add(movie15);

        //To register users
        member1=new Member("111-1111","xx","mamtha","xxx@gmail.com","9791891723");
        member2=new Member("111-1112","kk","madhu","yyy@gmail.com","9442130723");
        member3=new Member("111-1113","rr","shree","rrr@gmail.com","9647889123");
        member4=new Member("111-1114","rr","dhanya","bbb@gmail.com","9443145143");
        member.add(member1);
        member.add(member2);
        member.add(member3);
        member.add(member4);

    }

   public void view_books()     //Function to view the list of books in the library
    {
        int i;
        System.out.print("Book ID    Book Name           Author          Category");

        for(i=0;i<book.size();i++)
        {

            Book sel_book=book.get(i);
            System.out.println();
            System.out.print(sel_book.id+"\t\t\t"+sel_book.name+"\t\t\t"+sel_book.author+"\t\t\t" +sel_book.category);
        }
    }


     public Boolean is_bookavailable(int bid)        //Function to check the book requested by the customer is available
    {

       int i;
        for(i=0;i<book.size();i++)
        {
            Book sel_book=book.get(i);

            if(bid ==sel_book.id )
            {
                if(sel_book.quantity!=0)
                {
                     sel_book.quantity-=1;
                     book.set(i,sel_book);
                     return true;

                }
                else
                {
                    return false;
                }
            }

        }

        return false;

    }




    void view_movies()           //Function to view the list of movies available in the library
    {
        int i;
        System.out.print("Name        Year        Director       Rating");
        for(i=0;i<movie.size();i++)
        {

            Movie m=movie.get(i);
            System.out.println();
            System.out.print(m.name+"\t\t\t"+m.year+"\t\t\t"+m.director+"\t\t\t" +m.rating);

        }

    }

    public Boolean Authenticate_user(String uname,String pwd)       //Function to authenticate user

    {
        int i;
        for(i=0;i<member.size();i++)
        {
            Member membr=member.get(i);
            if(uname.equalsIgnoreCase(membr.uname) && pwd.equalsIgnoreCase(membr.password))
            {

                return true;
            }

        }

        return false;

    }

    void view_details(String un)        //Function to view the membership details
    {
        int i;
        for(i=0;i<member.size();i++)
        {
            Member membr=member.get(i);
            if(un.equalsIgnoreCase(membr.uname))
            {
                System.out.println("NAME:"+membr.name);
                System.out.println("EMAIL:"+membr.email);
                System.out.println("PHONE NO:"+membr.phno);
            }


        }
    }



}
